﻿using UnityEngine;
using System.Collections;
using DG.Tweening;//DOTween命名空间

public class TestTween : MonoBehaviour
{
    //tweeen的目标对象
    public Transform cubeA, cubeB , cubeC;
    private float num = 0;
    void Start()
    {
        //全局初始化
        DOTween.Init(false, true, LogBehaviour.Default).SetCapacity(200, 10);

        //快捷方式创建twee
        cubeA.DOMove(new Vector3(-2, 2, 0), 1).SetRelative().SetLoops(-1, LoopType.Yoyo);
        //通用方式创建tween
        //DOTween.To(() => cubeB.position, x => cubeB.position = x, new Vector3(-2, 2, 0), 1).SetRelative().SetLoops(-1, LoopType.Yoyo);

        DOTween.To(() => num, x => num = x, 5, 1);

        cubeA.GetComponent<Renderer>().material.DOColor(Color.red, 10);

        cubeC.DOShakePosition(1, 5, 10, 45).SetLoops(-1, LoopType.Restart);




        Sequence mySequence = DOTween.Sequence();

        mySequence.Append(cubeB.DOMoveX(5, 1))
          .AppendInterval(1)
          .Append(cubeB.DORotate(new Vector3(0, 180, 0), 1))
          .PrependInterval(1)
          .Insert(0, cubeB.DOScale(new Vector3(3, 3, 3), mySequence.Duration()));

        Debug.LogError(mySequence.Duration());
    }
    private void Update()
    {
        Debug.Log(num);
    }
}